package org.example.ttms.entityClass.ticket;

import org.example.ttms.customize.BuyTicket;
import org.example.ttms.customize.ChangeTicketWindow;
import org.example.ttms.customize.Pop_ups;

import java.util.Calendar;
import java.util.Date;

public class ChangeTicket extends Ticket{
    public static double price = 0.0;

    //改签流程
    public void changeTicket(Ticket ticket){
        Pop_ups popUps = new Pop_ups();
        //判断是否发车
        if(ticket.getStatus().equals("已出发")){
            popUps.pop_ups3("该车次已出发");
            return;
        }
        if(ticket.getStatus().equals("已到达")){
            popUps.pop_ups3("该车次已到达");
            return;
        }

        //判断是否退票
        if(ticket.getStatus().equals("已退票")){
            popUps.pop_ups3("该车次已退票");
            return;
        }
        if(!computeTime(ticket)){
            price = 20;
        }
        //进入改签页面
        ChangeTicketWindow change = new ChangeTicketWindow();
        change.changeTicketWindow(ticket);
    }
    //计算改签时间
    public boolean computeTime(Ticket ticket){
        Date today = new Date();
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(today);
        calendar.add(Calendar.DAY_OF_MONTH, 2);
        Calendar calendar2 = Calendar.getInstance();
        calendar2.setTime(ticket.getGoTime());
        return calendar.before(calendar2);
    }
    //确定改签
    public void change(Ticket delTicket, String type){
        //先退票
        RefundTicket refund = new RefundTicket();
        refund.delTicket(delTicket);
        //再买票
        BuyTicket buy = new BuyTicket();
        BuyTicket.trips = ChangeTicketWindow.trips;
        buy.buyTicket(type, "改签成功");
    }
}
